package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.constant.BedConstant;
import com.zzyl.dto.CreateBedDto;
import com.zzyl.dto.UpdateBedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import com.zzyl.vo.GetBedByIdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    @Override
    public void createBed(CreateBedDto dto) {
        Bed bed =  BeanUtil.copyProperties(dto, Bed.class);
        bed.setBedStatus(BedConstant.NOT_IN);
        bed.setCreateTime(LocalDateTime.now());
        bed.setUpdateTime(LocalDateTime.now());
        bedMapper.insert(bed);
    }

    @Override
    public GetBedByIdVo getById(Long id) {
        return bedMapper.getById(id);
    }

    @Override
    public void updateBed(UpdateBedDto dto) {
        Bed bed =  BeanUtil.copyProperties(dto, Bed.class);
        bed.setUpdateTime(LocalDateTime.now());
        bedMapper.update(bed);
    }

    @Override
    public void deleteById(Long id) {
        bedMapper.deleteById(id);
    }
}

